#pragma once
namespace html { namespace dom
{
  void selector::select (node _node, nodes& _out) const {
    // begin selection with the first selector applied to all children
    select(begin(),_node.children(),_out);
  }
  void selector::select (const_iterator itCriteria, const nodes_data& _in, nodes& _out ) const {
    // iterate all children
    for (nodes_data::const_iterator it_child=_in.begin(); it_child!=_in.end(); it_child++)
    {
      // check if the current criteria matches the current child
      if (*itCriteria==*it_child)
      {
        // last criteria?
        if( itCriteria+1 == end() )
        {
          // store the found child into the output container
          _out.push_back(*it_child);
          // continue to search by checking all descendants for the current criteria
          select(itCriteria,it_child->children(),_out);
        }
        else
          // check all children for the next criteria
          select(itCriteria+1,it_child->children(),_out);
      }
      else
        // check all children for the current criteria
        select(itCriteria,it_child->children(),_out);
    }
  }
} }
  